package wangjg.test.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class UDPClient {
	
	void testWlan() throws IOException{
		String targetIp = "210.13.116.210";
		DatagramSocket ds = new DatagramSocket(10001);
		int targetPort = 1024;
		while( ++targetPort <= 65535 ){
			String hello = "Hello world!";
			byte[] buf = hello.getBytes();
			InetSocketAddress target = new InetSocketAddress(targetIp, targetPort);
			DatagramPacket op = new DatagramPacket(buf, buf.length, target);
			ds.send(op);
			System.out.println("port="+targetPort);
		}
		ds.close();
	}
	
	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		String targetIp = "127.0.0.1";
		int targetPort = 6001;
		InetSocketAddress target = new InetSocketAddress(targetIp, targetPort);
		
		String hello = "Hello world!";
		byte[] buf = hello.getBytes();
		DatagramPacket op = new DatagramPacket(buf, buf.length, target);
		
		DatagramSocket ds = new DatagramSocket(10001);
		ds.send(op);
		ds.close();
	}

}
